const GitServer = require('./GitServer')
const GithubRequest = require('./GithubRequest')

class Github extends GitServer {
  constructor() {
    super('github') // super()调用父类的constructor， 传入type
    this.request = null
  }
  setToken(token) {
    super.setToken(token)
    this.request = new GithubRequest(token)
  }

  getUser() {
    return this.request.get('/user')
  }

  getOrg(username) {
    return this.request.get(`/users/orgs`, {
      page: 1,
      per_page: 100,
    })
  }

  getRemote(login, name) {
    return `git@github.com:${login}/${name}.git`
  }

  getTokenHelp() {
    return 'https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh'
  }
  getTokenUrl() {
    return 'https://github.com/settings/tokens'
  }
}

module.exports = Github
